package com.ruoyi.project.user.ioslog.service.impl;

import com.ruoyi.common.utils.IpUtils;
import com.ruoyi.common.utils.text.Convert;
import com.ruoyi.framework.aspectj.lang.annotation.DataSource;
import com.ruoyi.framework.aspectj.lang.enums.DataSourceType;
import com.ruoyi.project.user.ioslog.domain.IosLog;
import com.ruoyi.project.user.ioslog.mapper.IosLogMapper;
import com.ruoyi.project.user.ioslog.service.IIosLogService;
import net.ipip.ipdb.CityInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * iOS上报Service业务层处理
 *
 * @author shixiangwen
 * @date 2022-12-01
 */
@Service
@DataSource(DataSourceType.KKFORMULA)
public class IosLogServiceImpl implements IIosLogService {
    @Autowired
    private IosLogMapper iosLogMapper;

    /**
     * 查询iOS上报
     *
     * @param id iOS上报ID
     * @return iOS上报
     */
    @Override
    public IosLog selectIosLogById(Long id) {
        return iosLogMapper.selectIosLogById(id);
    }

    /**
     * 查询iOS上报列表
     *
     * @param iosLog iOS上报
     * @return iOS上报
     */
    @Override
    public List<IosLog> selectIosLogList(IosLog iosLog) {
        List<IosLog> logs = iosLogMapper.selectIosLogList(iosLog);
        logs.forEach(item -> {
            CityInfo cityInfo = IpUtils.getCityInfo(item.getIp());
            if (cityInfo != null) {
                item.setIpInfo(cityInfo.getRegionName() + " " + cityInfo.getCityName());
            }
        });
        return logs;
    }

    /**
     * 新增iOS上报
     *
     * @param iosLog iOS上报
     * @return 结果
     */
    @Override
    public int insertIosLog(IosLog iosLog) {
        return iosLogMapper.insertIosLog(iosLog);
    }

    /**
     * 修改iOS上报
     *
     * @param iosLog iOS上报
     * @return 结果
     */
    @Override
    public int updateIosLog(IosLog iosLog) {
        return iosLogMapper.updateIosLog(iosLog);
    }

    /**
     * 删除iOS上报对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteIosLogByIds(String ids) {
        return iosLogMapper.deleteIosLogByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除iOS上报信息
     *
     * @param id iOS上报ID
     * @return 结果
     */
    @Override
    public int deleteIosLogById(Long id) {
        return iosLogMapper.deleteIosLogById(id);
    }
}
